package com.wutma.friend.controller.user;

import com.wutma.common.core.controller.BaseController;
import com.wutma.common.core.domain.R;
import com.wutma.friend.domain.exam.dto.UserSubmitDTO;
import com.wutma.api.domain.vo.UserQuestionResultVO;
import com.wutma.friend.service.user.IUserQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("user/question")
@RestController
public class UserQuestionController extends BaseController {

    @Autowired
    private IUserQuestionService userQuestionService;

    /**
     * 提交代码
     */
    @PostMapping("/submit")
    public R<UserQuestionResultVO> submit(@RequestBody UserSubmitDTO userSubmitDTO) {
        return userQuestionService.submit(userSubmitDTO);
    }

    /**
     * 提交代码(rabbitMq版本，高效)
     */
    @PostMapping("/rabbit/submit")
    public R<Void> rabbitSubmit(@RequestBody UserSubmitDTO userSubmitDTO) {
        return toR(userQuestionService.rabbitSubmit(userSubmitDTO));
    }

    /**
     * 获取提交后代码执行结果
     */
    @GetMapping("/exe/result")
    public R<UserQuestionResultVO> exeResult(Long questionId, Long examId, String currentTime) {
        return R.ok(userQuestionService.exeResult(questionId, examId, currentTime));
    }
}
